<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2022/3/21
 */

namespace App\View\Components;

use Illuminate\View\Component;

/**
 * 轮播组件类
 * Class Carousel
 * @package App\View\Components
 */
class Carousel extends Component
{

    /**
     * id选择器名
     * @var
     */
    public $id = "";

    /**
     * class选择器名
     * @var
     */
    public $class = "";

    /**
     * 是否总是轮播，默认false
     * 说明：当列表中仅包含一条数据时是否总是轮播效果，默认0，0代表不轮播只展示一张图片，反之1总是轮播
     * @var bool
     */
    public $always = false;

    /**
     * 展示标题，默认true
     * @var bool
     */
    public $showTitle = true;

    /**
     * 展示描述，默认true
     * @var bool
     */
    public $showDesc = true;

    /**
     * 间隔时间（毫秒）
     * @var int
     */
    public $interval = 3000;


    /**
     * 轮播数据
     * @var
     * [
     *  [
     *      'name' => '', // 名称
     *      'href_' => '', // 链接代码
     *      'href_target_' => '', // 打开方式代码
     *      'rel_' => '', // 禁止搜索引擎跟踪链接代码
     *      'image_url' => '', // 图片访问地址
     *      'description' => '', // 描述
     *      ......
     *  ],
     * ]
     */
    public $list = [];

    /**
     * 名称字段
     * @var
     */
    public $name = 'name';

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($id = "", $class = "", $always = false, $showTitle = true, $showDesc = true, $list = [], $interval = 3000, $name = "")
    {
        $this->id = $id ?: $this->id;
        $this->class = $class ?: $this->class;
        $this->always = $always ?? $this->always;
        $this->showTitle = $showTitle ?? $this->showTitle;
        $this->showDesc = $showDesc ?? $this->showDesc;
        $this->list = $list ?: $this->list;
        $this->interval = $interval ?: $this->interval;
        $this->name = $name ?: $this->name;
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        return view('components.carousel');
    }
}
